<template>
  <div>
    <a-card :bordered="false">
      <f-table ref="table" rowKey="materialPackage100Id" :scroll="{x:1980,y:columns.length*35}"
               :columns="newColumns"
               :exportBtn="false"
               :multiple="false" :operator="operator" :params="queryParam" :api="api.bmp">
      </f-table>
    </a-card>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'bmpDetail',
    data: function() {
      let me = this
      //操作按钮
      let operator = []
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        // 表头
        newColumns: [],
        columns: [
          {
            title: '序号',
            width: 80,
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '分包Id',
            width: 180,
            align: 'center',
            dataIndex: 'materialPackage100Id'
          },
          {
            title: '项目代码',
            width: 150,
            align: 'center',
            dataIndex: 'projectCode'
          },
          {
            title: '项目名称',
            width: 150,
            align: 'center',
            dataIndex: 'projectName'
          },
          {
            title: '服务代码',
            width: 150,
            align: 'center',
            dataIndex: 'serviceCode'
          },
          {
            title: '服务WBS代码',
            width: 150,
            align: 'center',
            dataIndex: 'serviceWbsCode'
          },
          {
            title: '科目名称',
            width: 150,
            align: 'center',
            dataIndex: 'subjectName'
          },
          {
            title: '层级号',
            width: 150,
            align: 'center',
            dataIndex: 'levelNo'
          },
          {
            title: '分承包发包项目描述',
            width: 200,
            align: 'center',
            dataIndex: 'packageDesc'
          },
          {
            title: '区域',
            width: 150,
            align: 'center',
            dataIndex: 'materialArea'
          },
          {
            title: '系统',
            width: 150,
            align: 'center',
            dataIndex: 'materialUse'
          },
          {
            title: '标前工程量',
            width: 150,
            align: 'center',
            dataIndex: 'beforeMarkQuantity'
          },
          {
            title: '100预算成本工程量',
            width: 200,
            align: 'center',
            dataIndex: 'costQuantity100'
          }
        ],
        operator: operator
      }
    },
    created() {
      this.queryParam.isGroup = false
      this.queryParam.isReport = false
      this.initColumns()
    },
    methods: {
      initColumns() {
        let projectId = this.$route.query.projectId
        let majorCode = this.$route.query.majorCode
        let packageNo = this.$route.query.packageNo
        let versionId = this.$route.query.versionId
        let queryColumnsStr = this.$route.query.columns
        let params = {
          projectId: projectId,
          majorCode: majorCode,
          packageNo: packageNo,
          planType: 2,
          versionStatus: 0,
          versionId:versionId
        }
        this.queryParam = params
        this.http.get(this, {
          url: this.api.projectSupplier.getBusProjectSupplierList,
          data: {
            projectId: projectId,
            majorCode: majorCode,
            packageNo: packageNo
          },
          success(me, data) {
            console.log(data)
            for (let i in data) {
              let info = data[i]
              me.columns.push({
                title:info.supplierName + '合同量',
                width: 150,
                align: 'center',
                dataIndex: 'supplierNum' + info.index
              })
            }
            console.info('queryColumnsStr', queryColumnsStr)
            if (queryColumnsStr) {
              let newColumns = []
              let queryColumns = queryColumnsStr.split(',')
              me.columns.forEach(column => {
                let dataIndex = column.dataIndex
                queryColumns.forEach(queryColumn => {
                  if (dataIndex == queryColumn) {
                    newColumns.push(column)
                  }
                })
              })
              me.newColumns = newColumns
            } else {
              me.newColumns = me.columns
            }
            console.info('newColumns', me.newColumns)
          }
        })
      }
    }
  }
</script>
